#include "StdAfx.h"
#include "IPAnalyser.h"

void CIPAnalyser::Analyse(const u_char* data)
{
	if ((data[0] >> 4) == 4) // if IPv4
	{
		int iplen = ntohs(*(u_short*)&data[2]);
		if (data[9] == 6) // if TCP
		{
			int iphdrlen = (data[0] & 0x0F) * 4;
			int ip_src = ntohl(*(u_long*)(data + 12));
			int ip_dest = ntohl(*(u_long*)(data + 16));
			OnTCPData(ip_src, ip_dest, data + iphdrlen, iplen - iphdrlen);
		}
	}
}
